from app.extensions import db
from datetime import datetime
from app.models.model_mixin import BaseMixin

class Bills(db.Model, BaseMixin):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(255))
    payer_wxid = db.Column(db.String(255))
    out_trade_no = db.Column(db.String(255))
    fee = db.Column(db.String(255))
    remark = db.Column(db.String(255))
    payer_remark = db.Column(db.String(255))
    timestamp = db.Column(db.String(255))

    def to_dict(self, content=False):
        res_data = {
            'id': self.id,
            'title': self.title,
            'payer_wxid':  self.payer_wxid,
            'out_trade_no': self.out_trade_no,
            'fee': self.fee,
            'remark': self.remark,
            'payer_remark': self.payer_remark,
            'timestamp': self.timestamp
        }
        return res_data

    @staticmethod
    def to_collection_dict(query, page, per_page=10):
        resources = query.paginate(page, per_page, False)
        data = {
            'items': [item.to_dict() for item in resources.items]
        }
        return data
